let details = {
    init(){
        this.url = window.location.search;
        this.contentStr = {};
        this.getDetails(this.url);
        this.switch();
    },
    switch() {
        let that = this;
        $(".switch-btn-item").click(function () {
            console.log(2)
            if(!($(this).hasClass("active"))){
                $(this).siblings().removeClass('active');
                $(this).addClass('active');
                console.log($(this).hasClass("original"))
                if($(this).hasClass("original")){
                    $('.content').html(that.contentStr.original)
                }
                if($(this).hasClass("translation")){
                    console.log(2)
                    $('.content').html(that.contentStr.translation)
                }
            }

        })
    },
    getDetails(url){
        let that = this;
        let newsId = url.split('&')[1].split('=')[1];
        let type = url.split('&')[2]?url.split('&')[2].split('=')[1]:'';
        let index = url.split('&')[3]?url.split('&')[3].split('=')[1]:'';
        $.ajax({
            headers: {
                "token":''//此处放置请求到的用户token
            },
            url: Public.ctx +`/api/content/detail/${newsId}`,
            type: 'get',
            dataType: 'json',
            data:{
                index,
                type
            },
            success: (data) => {
                if(data.success === true){
                    console.log(data);
                    let v = data.data;
                    that.contentStr.translation = `<div class="mt">
                                                <h3 class="title">${v.translatitle}</h3>
                                                <dl class="info">
                                                    <dt>来源：</dt>
                                                    <dd>${v.release}</dd>
                                                    <dt>时间：</dt>
                                                    <dd>${v.time}</dd>
                                                </dl>
                                            </div>
                                            <div class="mc">
                                                ${v.translate}
                                            </div>
                                            <p class="tips">*本文版权及观点归原文著作作权人，不代表平台立场</p>`
                    that.contentStr.original = `<div class="mt">
                                                <h3 class="title">${v.title}</h3>
                                                <dl class="info">
                                                    <dt>Source：</dt>
                                                    <dd>${v.release}</dd>
                                                    <dt>Time：</dt>
                                                    <dd>${v.time}</dd>
                                                </dl>
                                            </div>
                                            <div class="mc">
                                                ${v.article}
                                            </div>
                                            <p class="tips">*The copyright and opinions of this article belong to the original copyright owner and do not represent the platform position</p>`
                    $('.content').html(that.contentStr.original)
                }else {
                   // Public.message();
                }
            }
        });
    }
}
details.init();

